import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/components/Login'
import Home from '@/components/Home'
import StuList from '@/components/student/StuList'
import stuRec from '@/components/record/stu_rec'
import recordList from '@/components/record/recordList'
import addRecord from '@/components/record/addRecord'
import updateRecord from '@/components/record/updateRecord'
import logout from '@/components/logout'

Vue.use(Router)
let router = new Router({
  routes: [
    {
      path: '/',
      name: 'Login',
      component: Login
    },
    {
      path: '/Home',
      name: 'Home',
      component: Home,
      children:[
        {path:"/manager/stu",name:"StuList",component:StuList,
          children:[{path:"/manager/stu/rec",name:"stuRec",component:stuRec}]
        },
        {path:"/manager/record",name:"recordList",component:recordList},
        {path:"/manager/addRecord",name:"addRecord",component:addRecord},
        {path:"/manager/updateRecord",name:"updateRecord",component:updateRecord},
        {path:"/manager/logout",name:"logout",component:logout}
      ]
    }
  ]
})

router.beforeEach((to, from, next) => {
  // 导航钩子，全局钩子
  let token = sessionStorage.getItem('token');
  if(!token){
    if(to.name != 'Login' && to.name != 'Signin' && to.name != 'Register'){
      next('/');
    }else{
      next();
    }
  }else{
    next();
  }
})
export default router
